﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Micro;
using System.ComponentModel.Composition;
using System.Windows.Media;
using System.Windows;
using FamilyShowSource.Events;

namespace FamilyShowSource.ViewModels
{
    [Export(typeof(MainViewModel))]
    public class MainViewModel : Conductor<object>.Collection.OneActive
    {
        #region Fields

        /// <summary>
        /// Reference to the Welcome view
        /// </summary>
        public WelcomeViewModel WelcomeViewModel { get; private set; }

        /// <summary>
        /// Reference to the OldVersionMessage view
        /// </summary>
        public OldVersionMessageViewModel OldVersionMessageViewModel { get; private set; }

        /// <summary>
        /// Reference to the NewUser view
        /// </summary>
        public NewUserViewModel NewUserViewModel { get; private set; }

        /// <summary>
        /// Reference to the Detail view
        /// </summary>
        public DiagramAndDetailViewModel DiagramAndDetailViewModel { get; private set; }

        #endregion

        #region Constructors

        /// <summary>
        /// This annotation to indicate that this constructor will be used.
        /// With this constructor, Caliburn Micro will execute the following:
        /// - Create instances of the Views and pass to the constructor
        /// </summary>
        /// <param name="welcomeViewModel"></param>
        /// <param name="oldVersionMessageViewModel"></param>
        /// <param name="newUserViewModel"></param>
        [ImportingConstructor]
        public MainViewModel(WelcomeViewModel welcomeViewModel, OldVersionMessageViewModel oldVersionMessageViewModel,
                             NewUserViewModel newUserViewModel, DiagramAndDetailViewModel detailViewModel)
        {
            this.WelcomeViewModel = welcomeViewModel;
            this.OldVersionMessageViewModel = oldVersionMessageViewModel;
            this.NewUserViewModel = newUserViewModel;
            this.DiagramAndDetailViewModel = detailViewModel;
            this.ActivateItem(welcomeViewModel);

            // Subscrive custom events
            this.SubscribeNotifyActivateNewUserEvent();
            this.SubscribeNotifyActivateDiagramAndDetailEvent();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Subscribe this event to active the NewUser view
        /// </summary>
        private void SubscribeNotifyActivateNewUserEvent()
        {
            EventAggregatorFactory.Instance.GetEvent<NotifyActivateNewUserEvent>()
                .Subscribe((eventData) => this.ActivateItem(this.NewUserViewModel), false);
        }

        /// <summary>
        /// Subscribe this event to active the Detail view
        /// </summary>
        private void SubscribeNotifyActivateDiagramAndDetailEvent()
        {
            EventAggregatorFactory.Instance.GetEvent<NotifyActivateDiagramAndDetailEvent>()
                .Subscribe((eventData) => this.ActivateItem(this.DiagramAndDetailViewModel), false);
        }

        #endregion
    }
}
